package com.example.javatest.utils;

import com.example.javatest.entity.domain.TbUser;

import javax.servlet.http.HttpServletRequest;

import static com.example.javatest.constant.UserConstant.*;

public class RoleCheck {

    //是否是管理员
    public static boolean isAdmin(HttpServletRequest httpServletRequest){
        Object userObject =httpServletRequest.getSession().getAttribute(USER_LOGIN_STATE);
        TbUser tbUser = (TbUser) userObject;
        return tbUser != null && tbUser.getUserIdentity().equals(ADMIN_ROLE);
    }

    //是否是教师
    public static boolean isTeacher(HttpServletRequest httpServletRequest){
        Object userObject =httpServletRequest.getSession().getAttribute(USER_LOGIN_STATE);
        TbUser tbUser = (TbUser) userObject;
        return tbUser != null && tbUser.getUserIdentity().equals(TEACHER_ROLE);
    }

    //是否是家长
    public static boolean isParent(HttpServletRequest httpServletRequest){
        Object userObject =httpServletRequest.getSession().getAttribute(USER_LOGIN_STATE);
        TbUser tbUser = (TbUser) userObject;
        return tbUser != null && tbUser.getUserIdentity().equals(PARENT_ROLE);
    }
}
